sub utf8FileDemo
Dim fileNum As Integer
Dim filePath
fileNum% = Freefile()
filePath = 
Open filePath For Output As fileNum% Charset = "UTF-8"
end sub

DECLARATIONS

Const OS_TRANSLATE_NATIVE_TO_LMBCS=0	'Translate platform-specific to LMBCS
Const OS_TRANSLATE_LMBCS_TO_NATIVE=1	'Translate LMBCS to platform-specific
Const OS_TRANSLATE_LOWER_TO_UPPER=3	'current int'l case table
Const OS_TRANSLATE_UPPER_TO_LOWER=4	'current int'l case table
Const OS_TRANSLATE_UNACCENT=5 'int'l unaccenting table
Const OS_TRANSLATE_LMBCS_TO_UNICODE=20
Const OS_TRANSLATE_LMBCS_TO_UTF8=22
Const OS_TRANSLATE_UNICODE_TO_LMBCS=23
Const OS_TRANSLATE_UTF8_TO_LMBCS=24

Declare Function OSTranslateToLMBCS% Lib "nnotes" _
Alias "OSTranslate" (Byval nTranslateMode%, Byval dwIn$, Byval nLength%, Byval lpszOut As Lmbcs String, Byval nOutLength%) 
Declare Function OSTranslateToUTF8% Lib "nnotes" _
Alias "OSTranslate" (Byval nTranslateMode%, Byval dwIn As Lmbcs String, Byval nLength%, Byval lpszOut As String, Byval nOutLength%) 


Function ConvertLineEncoding(InputLine As String, ConvertString As String, LineLen As Integer, EncodingConv As String) As Integer
Dim fullLine As String 
Dim ConvertedLine As String
Dim ConvertedLineEndPos As Long
Dim EncodingConvertCode As Integer

ConvertLineEncoding=0

ConvertedLine=String(linelen,0)
Select Case EncodingConv
Case "UTF8_TO_LMBCS"
EncodingConvertCode=OS_TRANSLATE_UTF8_TO_LMBCS
Call OSTranslateToLMBCS(EncodingConvertCode, Byval InputLine, linelen, Byval ConvertedLine, linelen)
Case "UNICODE_TO_LMBCS"
EncodingConvertCode=OS_TRANSLATE_UNICODE_TO_LMBCS
Call OSTranslateToLMBCS(EncodingConvertCode, Byval InputLine, linelen, Byval ConvertedLine, linelen)
Case "LMBCS_TO_UTF8"
EncodingConvertCode=OS_TRANSLATE_LMBCS_TO_UTF8
Call OSTranslateToUTF8(EncodingConvertCode, Byval InputLine, linelen, Byval ConvertedLine, linelen)
End Select

ConvertedLineEndPos=Instr(ConvertedLine,Chr$(0))
If ConvertedLineEndPos>1 Then
ConvertString=Left(ConvertedLine, ConvertedLineEndPos-1)	
Else
ConvertString=ConvertedLine
End If

End Function


Sample calls to this function:

Line Input #fileNum%, txt$
Call ConvertLineEncoding(txt, txt, Len(txt), "UTF8_TO_LMBCS")


Call ConvertLineEncoding(txt, txt, 3*Len(txt), "LMBCS_TO_UTF8")


Function Utf8Decode(s As String) As String
 Dim i As Integer
 Dim tmp As String
 Dim c As String
 tmp = ""
 For i = 1 To Len(s)
  c = Mid$(s, i, 1)
  If c = "+" Then
   c = " "
  Elseif c = "%" Then
   c = Mid$(s, i + 1, 2)
   If (Val("&H" & c) >= 0) And (Val("&H" & c) <= Val("&H7F")) Then
    c = Uchr$("&H" & c)
    i = i + 2
   Elseif (Val("&H" & c) >= Val("&HC0")) And (Val("&H" & c) <= Val("&HDF")) Then
    c = Right(Bin$(Val("&H" & Mid$(s, i + 1, 2))),5)
    c = c & Right(Bin$(Val("&H" & Mid$(s, i + 4, 2))),6)
    c = Uchr$("&B" & c)
    i = i + 5
   Elseif (Val("&H" & c) >= Val("&HE0")) And (Val("&H" & c) <= Val("&HEF")) Then
    c = Right(Bin$(Val("&H" & Mid$(s, i + 1, 2))),4)
    c = c & Right(Bin$(Val("&H" & Mid$(s, i + 4, 2))),6)
    c = c & Right(Bin$(Val("&H" & Mid$(s, i + 7, 2))),6)
    c = Uchr$("&B" & c)
    i = i + 8
   Else
    c = Mid$(s, i, 3)
    i = i + 2
   End If
  End If
  tmp = tmp + c
 Next i
 Utf8Decode = tmp
End Function